public class Offer24 {

    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    class Solution {
        ListNode res = null;
        public ListNode dfs(ListNode head){
            if(head.next == null && res == null){
                res = head;
                return head;
            }

            ListNode cur=dfs(head.next);
            cur.next=head;
            head.next = null;
            return head;
        }
        public ListNode reverseList(ListNode head) {
            /**
             注意判空，教训
             */
            if(head==null){
                return null;
            }
            dfs(head);
            return res;

        }
    }

}
